using System.Collections.Generic;
using Script.Other;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public static GameManager instance;

    private GameSystem            gameSystem;
    private FixedUpdateGameSystem fixGameSys;
    private Contexts              _contexts;

    public static Contexts contexts => instance._contexts;

    private void Awake ()
    {
        if (instance!=null)
        {
            Destroy (instance.gameObject);
        }

        instance = this;

        _contexts   = Contexts.sharedInstance;
        _contexts.SubscribeId ();

        var physicEntity = _contexts.physics.CreateEntity ();
        physicEntity.AddPhysicComp (new List<CollisionInfo> ());
        
        fixGameSys=new FixedUpdateGameSystem (_contexts);
        gameSystem = new GameSystem (_contexts);
    }

    private void Start ()
    {
        gameSystem.Initialize ();
    }
    
    private void FixedUpdate ()
    {
        fixGameSys.Execute ();
        fixGameSys.Cleanup ();
    }

    private void Update ()
    {
        gameSystem.Execute ();
        gameSystem.Cleanup ();
    }
    
    private void OnDestroy ()
    {
        gameSystem.TearDown ();
    }
}
